using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace DatabaseManager.UI
{
    /// <summary>
    /// Simple control, which holds a textbox and a button to perform a search.
    /// This control is designed for beeing displayed in a status bar.
    /// </summary>
    public partial class Quicksearch : UserControl
    {
        /// <summary>
        /// Occurs when the search button is clicked or the enter key is pressed.
        /// </summary>
        public event EventHandler SearchPerformed;

        /// <summary>
        /// Initializes a new instance of the <see cref="Quicksearch"/> class.
        /// </summary>
        public Quicksearch()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the search text, which is displayed in the textbox.
        /// </summary>
        /// <value>The search text.</value>
        public string SearchText
        {
            get { return txtSearch.Text; }
            set { txtSearch.Text = value; }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            PerformSearch();
        }

        /// <summary>
        /// Raises the SearchPerformed event.
        /// </summary>
        public void PerformSearch()
        {
            if (SearchPerformed != null)
            {
                SearchPerformed(this, EventArgs.Empty);
            }
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                PerformSearch();
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }

    }
}
